package edu.upc.fib.lamsandroid.client.fragment;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import edu.upc.fib.lamsandroid.client.LamsAndroidClientApplication;
import edu.upc.fib.lamsandroid.client.R;
import edu.upc.fib.lamsandroid.client.activity.LessonActivity;
import edu.upc.fib.lamsandroid.server.api.model.Lesson;

public class LessonSummary extends Fragment {

    Lesson lesson;

    public LessonSummary() {
        lesson = null;
    }

    public LessonSummary(Lesson lesson) {
        this.lesson = lesson;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if(lesson == null) {
            return inflater.inflate(R.layout.lesson_summary_placeholder, container, false);
        } else {
            View view = inflater.inflate(R.layout.lesson_summary, container, false);

            TextView tv = (TextView) view.findViewById(R.id.lessonTitle);
            tv.setText(lesson.getTitle());

            tv = (TextView) view.findViewById(R.id.lessonDescription);
            tv.setText(lesson.getDescription());

            /*
             */

            Button btnOpen = (Button) view.findViewById(R.id.buttonOpen);
            btnOpen.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    LamsAndroidClientApplication.getInstance().setCurrentLesson(lesson);
                    startActivity(new Intent(getActivity(), LessonActivity.class));
                    getActivity().finish();
                }
            });

            return view;
        }
    }
}
